﻿using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Voice
{
    public delegate void AudouCapturedFunc(VoiceCapturedEventArgs e);

    [Serializable]
    public class VoiceCapturedEventArgs : EventArgs
    {
        public byte[] Source { get; set; }
        public int IndexMessage;
        #region Serialize/Deserialize

        public static byte[] Serialize(VoiceCapturedEventArgs source)
        {
            byte[] Rezult;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, source);
                Rezult = ms.ToArray();
                ms.Flush();
            }
            return Rezult;
        }

        public static VoiceCapturedEventArgs Deserialise(byte[] source)
        {
            VoiceCapturedEventArgs Rezult;
            
            using (MemoryStream ms = new MemoryStream(source))
            {
                BinaryFormatter bf = new BinaryFormatter();
                Rezult = bf.Deserialize(ms) as VoiceCapturedEventArgs;
                ms.Flush();
            }
                return Rezult;

        }
        #endregion
    }
}
